package com.example.sup.conttroller.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.io.Serializable;

/**
 * @ClassName ServerResponse
 * @Description {TODO}
 * @Author 李哲
 * @Date 15:14 2024/7/19
 * @Version 1.0
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ServerResponse<E> implements Serializable {
    private String flag;
    private String msg;
    private E data;

    private ServerResponse(String flag, String msg, E data) {
        this.flag = flag;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 成功响应
     */
    public static <E> ServerResponse<E> success(E data) {
        return new ServerResponse<>("true", "操作成功", data);
    }
    /**
     * 自定义成功响应
     */
    public static <E> ServerResponse<E> successWithMsg(String msg, E data) {
        return new ServerResponse<>("true", msg, data);
    }

    /**
     * 失败响应
     */
    public static <E> ServerResponse<E> fail(String msg) {
        return new ServerResponse<>("false", msg, null);
    }

    /**
     * 自定义失败响应
     */
    public static <E> ServerResponse<E> failWithMsg(String msg) {
        return new ServerResponse<>("false", msg, null);
    }




}
